from core.excel_data import ExcelData
from core.excel_handler import ExcelHandler
from core.filtered_value_cell_data_handler import FilteredValueCellDataHandler
from core.letter_match_item import LetterMatchItem
from core.match_value_cell_data_handler import MatchValueCellDataHandler
from core.simple_equals import SimpleEquals

if __name__ == '__main__':
    # handler = MatchValueCellDataHandler(
    #     ExcelData('/Users/venus/Desktop/小学查验工作.xlsx', '学生基础信息', 2),
    #     (LetterMatchItem('A', 'A'),),
    #     'G'
    # )
    #
    # def random(t: tuple) -> int:
    #     identity = handler.handle(t)
    #     if isinstance(identity, str):
    #         identity = identity.strip()
    #
    #     if int(identity[-2]) % 2 == 0:
    #         return randint(0, 1)
    #     return randint(2, 5)
    eq = SimpleEquals()
    excelData = ExcelData('/Users/venus/Downloads/莎车县塔尕尔其镇克塔提小学2019秋季学生调查摸底表.xlsx', '学生花名册', 5)
    data = ExcelHandler('/Users/venus/Desktop/小学查验工作.xlsx', 'Sheet1')
    data.fill_column_values(
        column_dimension='B',
        data_row_number=6,
        handler=FilteredValueCellDataHandler(
            excelData,
            lambda t: t[1] and t[1].strip() != '',
            'B'
        )
        # handler=RandomValueCellDataHandler(
        #     ('唱歌', '跳舞', '羽毛球', '篮球', '足球', '乒乓球'),
        #     lambda t: random(t)
        # )
    )
    data.fill_column_values(
        column_dimension='C',
        data_row_number=6,
        handler=MatchValueCellDataHandler(
            excelData,
            (LetterMatchItem('B', 'B'),),
            'E',
            lambda val: '女' if bool(val) and int(val[-2]) % 2 == 0 else '男'
        )
    )

    data.save('result.xlsx')
